package com.demo.jingxi.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    //状态码
    private Integer code ;

    //消息提示
    private String message ;

    //数据  List ， Map， String ， Book ， Student
    private T data ;

    //操作成功，没有数据返回
    public static<T> Result<T> success(){
        return new Result<>(20000, "操作成功" ,null);
    }

    //操作成功，返回数据
    public static<T> Result<T> success(T data){
        return new Result<>(20000, "操作成功" ,data);
    }

    public static<T> Result<T> success(String message){
        return new Result<>(20000, message ,null);
    }

    public static<T> Result<T> success(String message, T data){
        return new Result<>(20000, message ,data);
    }

    public static<T> Result<T> success(Integer code , String message, T data){
        return new Result<>(code, message ,data);
    }

    public static<T> Result<T> fail(){
        return new Result<>(60204, "操作失败" ,null);
    }

    public static<T> Result<T> fail(String message){
        return new Result<>(60204, message ,null);
    }

    public static<T> Result<T> fail(Integer code , String message){
        return new Result<>(code , message , null);
    }

    public static<T> Result<T> fail(Integer code , String message, T data){
        return new Result<>(code , message , data);
    }

}
